<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    #include("common/header.html")
</head>

<body>
<div style="margin: 15px;">
    <div class="layui-form" id="form">
        <div class="layui-form-item">
            <label class="layui-form-label">图片</label>
            <div class="layui-input-block">
                <img id="imgUrl" src="" data-src="" height="200px" width="200px">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
                <input type="file" name="file" id="imgFile" class="layui-upload-file">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block">
                <input type="text" id="title" is-yz="true" yz-type="null"  lay-verify="title" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
    </div>
</div>
<script>

    var layer;
    var form;
    layui.use(['layer','form', 'upload'], function () {
        layer = layui.layer;
        form = layui.form()

        layui.upload({
            url: '/upload/',
            elem: '#imgFile',
            success: function (res) {

                layer.msg(res.msg);

                if(res.code == -1){
                    return;
                }

                $("#imgUrl").attr("src",res.data);
                $("#imgUrl").attr("data-src",res.data);
                console.log(res); //上传成功返回值，必须为json格式
            }
        });
    });

</script>
</body>

</html>